using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.JavaScript;
using Avalonia;
using Avalonia.Collections;
using CommunityToolkit.Mvvm.ComponentModel;
using Material.Icons;
using Microsoft.Extensions.DependencyInjection;
using welog.core;
using welog.core.model;

namespace welog.Features.ControlsLibrary;

public partial class MarkDownViewModel:WelogPageBase
{
    private const string DefaultText = "";
    [ObservableProperty] private string _text = DefaultText;
    [ObservableProperty] private string _selectedSimpleContent;
    [ObservableProperty] private bool _isShow;
    public AvaloniaList<LogTreeNode> TreeViewContent { get; } = new();
    public AvaloniaList<string> SimpleContent { get; } = new();

    public MarkDownViewModel():base("日志",MaterialIconKind.LanguageMarkdown)
    {
        IsShow = true;
        
        var logDate = DateTime.Now;
        
        var myapp = Application.Current as App;
        var welogHandle = myapp.ServiceProvider.GetRequiredService<WelogHandle>();
        var welogConfig = myapp.ServiceProvider.GetRequiredService<SysConfig>();
        
        var plugins = myapp.ServiceProvider.GetServices<IWelogTextPlugin>().ToList();
        plugins.ForEach(plugin=>plugin.Config(welogConfig));
        welogHandle.WelogTextPlugins = plugins;
        
        welogHandle.AddMarkDownFileByCurrentTime(welogConfig.BaseDir, welogConfig.TempletePath);
        
        TreeViewContent.AddRange(welogHandle.GetLogTreeNodes(welogConfig.BaseDir));
    }
    
}